//
//  SZClassicLinesController.m
//  KaiJing
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "SZClassicLinesController.h"
#import <MJExtension.h>
#import "PKRequestManager.h"
#import "SZClassicLinesMainModel.h"
#import "SZClassicLinesMainCell.h"

#define kClassicLinesURL @"http://morguo.com/forum.php?mod=movielines&androidflag=1&appfrom=ios&iosversion=3.13&page=1"

@interface SZClassicLinesController ()
/** 数据源 */
@property (nonatomic, strong) NSMutableArray *dataSource;


@end

@implementation SZClassicLinesController
// 懒加载
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[SZClassicLinesMainCell class] forCellReuseIdentifier:@"SZClassicLinesMainCell"];
    
    [self setupData];
}

/**
 *  解析数据
 */
- (void)setupData {
    [PKRequestManager requestWithUrlString:kClassicLinesURL parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        SZLog(@"%@",dataDic);
        self.dataSource = [SZClassicLinesMainModel mj_objectArrayWithKeyValuesArray:dataDic[@"data"][@"list"]];
        [self.tableView reloadData];
    } error:^(NSError *error) {
        SZLog(@"%@",error);
    }];
}


#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SZClassicLinesMainCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SZClassicLinesMainCell" forIndexPath:indexPath];
    cell.model = _dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScreenWidth + 10;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.contentView.transform = CGAffineTransformMakeScale(0.01f, 0.01f);//将要显示的view按照正常比例显示出来
    [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //InOut 表示进入和出去时都启动动画
    [UIView setAnimationDuration:0.5f];//动画时间
    cell.contentView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);//先让要显示的view最小直至消失
    [UIView commitAnimations]; //启动动画
}
@end
